<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layuiAdmin 后台管理员</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="__STATIC__/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="__STATIC__/layuiadmin/style/admin.css" media="all">
  <style>

    .layui-textarea{ min-height: 190px;}
  </style>
</head>
<body>

<table class="layui-hide" id="wxList" lay-filter="wxList"></table>

<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>

</script>



<form class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">

  <div class="layui-form-item layui-form-text">

      <label class="layui-form-label">微信号</label>
      <input type="hidden" name="gid" value="{$gid}">
      <div class="layui-input-block">
        <textarea name="wx" placeholder="请输入微信号，每个微信号用回车分开，切记，切记~~~
        例如:
        123456
        888888
        567
        " class="layui-textarea"></textarea>
      </div>

  </div>


  <div class="layui-form-item">
    <div class="layui-input-block">
      <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>

  <div class="layui-form-item layui-hide">
    <input type="button" lay-submit lay-filter="LAY-wx-create-submit" id="LAY-wx-create-submit" value="确认">
  </div>
</form>


 <script src="__STATIC__/layuiadmin/layui/layui.js"></script>
  <script>
  layui.config({
    base: '__STATIC__/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table','upload'], function(){
    var $ = layui.$
    ,form = layui.form
    ,table = layui.table;



    //监听提交
    form.on('submit(demo1)', function(data){
      console.log(data.field);
      $.ajax({
        url:"addAll",
        type:"POST",
        dataType:"json",
        data:data.field,
        success:function (res) {
          console.log(res);
          if (res.code == 1 ){
            layer.msg(res['msg'],{icon: 1,time: 1000 },function () {
              $("#layuiadmin-form-admin")[0].reset();
              $('#img').attr('src', '');
              layui.form.render();
              table.reload('wxList');

            });
          }
        }
      });

      return false;
    });


    //获取添加后的微信号
    table.render({
      elem: '#wxList'
      ,url:'catchOne?gid='+{$gid}
      ,method:"post"
      // ,toolbar: '#barDemo' //开启头部工具栏，并为其绑定左侧模板
      ,title: '微信列表'
      ,cols: [[
        { title:'ID', fixed: 'left', type:'numbers'}
        // ,{field:'levelName', title:'目录_结构',templet: '#titleTpl' }
        ,{field:'id', hide: true}
        ,{field:'number', title:'微信号'}
        ,{field:'name', title:'客服名称' }
        ,{field:'imgurl', title:'二维码地址',width:130 }
        ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:80}
      ]]
      ,page: false
    });

    table.on('tool(wxList)', function(obj){
      var data = obj.data;
      console.log(data);
      if(obj.event === 'del'){
        layer.msg('122');
        layer.confirm('确认删除该条微信号吗？删除后将无法返回！', function(index){
          $.ajax({
            type: "GET",
            url:'deleteWx',
            data:data,
            dataType:"json",
            success:function (res) {
              if (res['code']==1){
                layer.msg(res['msg'],{icon: 1,time: 1000 },function () {
                  obj.del();
                  layer.close(index);
                });
              }else {
                layer.msg(res['msg'],{icon: 2,time: 1000 });
              }
            }
          });
        });
      }
    });

  });
  </script>
</body>
</html>

